import { defineStore } from 'pinia';
import { OrderMessage, Role } from 'app/typings';

export const useStore = defineStore({
  id: 'global',
  state: () => ({
    name: '',
    role: 'guest' as Role,
    phone: '',
    address: '',
    messages: [] as OrderMessage[],
  }),
  getters: {
    isGuest: (state) => state.role === 'guest',
    isUser: (state) => state.role === 'user',
    isAdmin: (state) => state.role === 'admin',
  },
  actions: {
    setName(name: string) {
      this.name = name;
    },
    setRole(role: Role) {
      this.role = role;
    },
    setPhone(phone: string) {
      this.phone = phone;
    },
    setAddress(address: string) {
      this.address = address;
    },
    setMessages(messages: OrderMessage[]) {
      this.messages = messages;
    },
  },
});
